package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.commands.PicInstruction;
import de.dhbw.karlsruhe.picsim.model.cpu.PicInstructionFacade;
import de.dhbw.karlsruhe.picsim.util.Bits;
import de.dhbw.karlsruhe.picsim.util.impl.Lengths;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: Apr 21, 2010
 * Time: 8:28:51 PM
 */
public final class Call implements PicInstruction {
    private final Bits argument;

    public Call(final Bits argument) {
        this.argument = argument;
        if (argument.getLength() != Lengths.CALL_GOTO_ARGUMENT_LENGTH) {
            throw new IllegalArgumentException();
        }
    }

    @NotNull
    @Override
    public List<? extends PicAction> getActions(@NotNull final PicInstructionFacade pic) {
        final List<PicAction> result = new ArrayList<PicAction>();
        result.add(pic.getActionFactory().createPushToStackAction());
        result.add(pic.getActionFactory().createElevenBitJump(argument));
        return Collections.unmodifiableList(result);
    }
}
